package com.goodving.guli.view;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.goodving.guli.R;
import com.goodving.guli.model.DeviceSource;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by john on 2015/11/24.
 */
public class GuliDevicesListAdapter extends BaseAdapter { // C1820X
    private final Context mContext;
    private final LayoutInflater mLayoutInflater;
    private final List<GuliHardwareDeviceItem> deviceList;

    class HwDeviceBundleView {
        public ImageView imageView;
        public TextView deviceNameTv;
        public TextView bindStatusTv;
        final /* synthetic */ GuliDevicesListAdapter deviceListAdapter;

        public HwDeviceBundleView(GuliDevicesListAdapter guliDevicesListAdapter) {
            this.deviceListAdapter = guliDevicesListAdapter;
        }
    }

    public GuliDevicesListAdapter(Context context) {
        this.mContext = context;
        this.mLayoutInflater = (LayoutInflater) this.mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.deviceList = new ArrayList();
    }

    public class GuliHardwareDeviceItem { // C1822Z
        public GuliHardwareDevice guliHardwareDevice;
        public Drawable drawable;
        public String deviceName;
        public boolean bindStatus;
//            public C1630e f9467e;
        final /* synthetic */ GuliDevicesListAdapter listAdapter;

        private GuliHardwareDeviceItem(GuliDevicesListAdapter listAdapter) {
            this.listAdapter = listAdapter;
        }
    }

    public void refreshDeviceList() { // m14250a
        this.deviceList.clear();
        // add ring
        GuliHardwareDeviceItem guliHardwareDeviceItem = new GuliHardwareDeviceItem(this);
        Resources resources = this.mContext.getResources();
//        guliHardwareDeviceItem.guliHardwareDevice = GuliHardwareDevice.RING;
//        guliHardwareDeviceItem.drawable = resources.getDrawable(R.drawable.ic_devices_bind_band);
//        guliHardwareDeviceItem.deviceName = resources.getString(R.string.ring);
//        guliHardwareDeviceItem.bindStatus = DeviceSource.hasBindBracelet();
//        this.deviceList.add(guliHardwareDeviceItem);

        // add scale
        guliHardwareDeviceItem = new GuliHardwareDeviceItem(this);
        guliHardwareDeviceItem.guliHardwareDevice = GuliHardwareDevice.SCALE;
        guliHardwareDeviceItem.drawable = resources.getDrawable(R.drawable.ic_devices_bind_weight);
        guliHardwareDeviceItem.deviceName = resources.getString(R.string.scale);
        guliHardwareDeviceItem.bindStatus = DeviceSource.hasBindWeight();
        this.deviceList.add(guliHardwareDeviceItem);

    }

    public int getCount() {
        return this.deviceList.size();
    }

    public Object getItem(int i) {
        return this.deviceList.get(i);
    }

    public long getItemId(int i) {
        return (long) i;
    }

    public View getView(int i, View view, ViewGroup viewGroup) {
        HwDeviceBundleView abVar;
        if (view == null) {
            view = this.mLayoutInflater.inflate(R.layout.device_list_item, null);
            abVar = new HwDeviceBundleView(this);
            abVar.imageView = (ImageView) view.findViewById(R.id.device_icon);
            abVar.deviceNameTv = (TextView) view.findViewById(R.id.device_name);
            abVar.bindStatusTv = (TextView) view.findViewById(R.id.bind_state);
            view.setTag(abVar);
        } else {
            abVar = (HwDeviceBundleView) view.getTag();
        }
        GuliHardwareDeviceItem guliHardwareDeviceItem = (GuliHardwareDeviceItem) this.deviceList.get(i);
        abVar.imageView.setImageDrawable(guliHardwareDeviceItem.drawable);
        abVar.deviceNameTv.setText(guliHardwareDeviceItem.deviceName);
        Resources resources = this.mContext.getResources();
        if (guliHardwareDeviceItem.bindStatus) {
            abVar.bindStatusTv.setText(resources.getString(R.string.state_binded));
            abVar.deviceNameTv.setTextColor(resources.getColor(R.color.font_color_c8));
            abVar.bindStatusTv.setTextColor(resources.getColor(R.color.font_color_c8));
            abVar.imageView.setAlpha(1.0f);
        } else {
            abVar.bindStatusTv.setText(resources.getString(R.string.state_unbinded));
            abVar.deviceNameTv.setTextColor(resources.getColor(R.color.font_color_c8_transparent));
            abVar.bindStatusTv.setTextColor(resources.getColor(R.color.font_color_c8_transparent));
            abVar.imageView.setAlpha(0.5f);
        }
        return view;
    }
}

